<template>
  <el-form-item :label="i18nt('designer.setting.maxValue')">
    <el-input-number v-model="maxValue" @change="validatePropValue" 
                     class="hide-spin-button" style="width: 100%"></el-input-number>
  </el-form-item>
</template>

<script>
  import i18n from "@/utils/i18n"

  export default {
    name: "max-editor",
    mixins: [i18n],
    props: {
      designer: Object,
      selectedWidget: Object,
      optionModel: Object,
    },
    computed: {
      maxValue: {
        get() {
          return this.optionModel['max']
        },

        set(newValue) {
          if (!newValue || isNaN(newValue)) {
            this.optionModel.max = null
          } else {
            this.optionModel.max = Number(newValue)
          }
        }
      },

    },
    methods: {
      validatePropValue(value, oldValue) {
        if ((this.optionModel.min  || this.optionModel.min == 0)
              && (this.optionModel.min > this.optionModel.max)) {
          this.$message.error( this.i18nt('designer.hint.maxValueError') )
          this.optionModel.max = oldValue
        } else {
          if (this.optionModel.max < this.optionModel.defaultValue) {
            this.optionModel.defaultValue = this.optionModel.max
          }
        }
      },
    }
  }
</script>

<style scoped>

</style>
